<?php

/*
 * Example code that access the API and outputs all
 * user workouts in a list
 */

/*
 * Please fill in these values
 */
$email = 'user@email.address.com';
$password = 'password';

$appKey = 'appkey1234567890';
$appSecret = 'appsecret1234567890';
/*
 * No need to modify values past here
 */

global $RA;

require_once('../includes/runningAhead.php');

try {
	// Initiates a new RunningAhead object and authenticates to the server
	$RA = new RunningAhead($appKey, $appSecret, 1);
	
	// Specifies which user you are impersonating and subsequently which users information you are requesting/modifying
	$RA->impersonateUser($email, $password);
	
	// Calls the listWorkouts() function to retrieve Date, Distance and Duration for all workouts
	$workouts = $RA->listWorkouts(array('Date', 'Distance', 'Duration'));

	// Loops through each workout and outputs the information
	foreach ($workouts as $workout) {
		echo 'Date: '.$workout['Date'].'<br />';
		echo 'Distance: '.$workout['Distance'].' '.$workout['DistanceUnit'].'<br />';
		if (isset($workout['Duration']))
			echo 'Duration: '.$workout['Duration'].'<br />';
		echo '<br />';
	}
	
	// Terminates session (Calls destructor). This should ALWAYS be done at the end!
	unset($RA);
} catch(Exception $e) {
	// Terminates session (Calls destructor). This should ALWAYS be done if the program will terminate!
	unset($RA);
	
	// Output the error message
	echo "<br>\n".$e->getMessage()."<br>\n";
}
?>